import { ref } from 'vue'
import { defineStore } from 'pinia'
import {getUserInformationService} from "@/api/user"

export const useUserStore=defineStore('userStore',()=>{
    const userId=ref('')
    const information=ref({})
    const getInformation=async()=>{
        const res=await getUserInformationService(userId.value)
        information.value=res.data
    }
    const setInformation=(value)=>{
        information.value=value
    }
    const removeInformation=()=>{
        information.value=null
    }
    const setUserId=(value)=>{
        userId.value=value
    }
    const removeUserId=()=>{
        userId.value=null
    }
    const  token=ref('')
    const setToken = (obj)=>{
        token.value=obj
    }
    const removeToken=()=>{
        token.value=null
    }
    return{
        userId,
        setUserId,
        removeUserId,
        token,
        setToken,
        removeToken,
        information,
        getInformation,
        setInformation,
        removeInformation

    }
},
//持久化
{
    persist: true
}
) 